import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/layout'


/**
 * @author chuzhixin 1204505056@qq.com
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，pro版只支持remixIcon图标
 * hidden:true                    是否显示在菜单中显示路由（默认值：false）
 * alwaysShow:true                当只有一级子路由时是否显示父路由是否显示在菜单中显示路由（默认值：false）
 * name:"Demo"                    首字母大写，一定要与vue文件的name对应起来，用于noKeepAlive缓存控制（该项特别重要）
 * meta:{
    title:"title"                 菜单、面包屑、多标签页显示的名称
    roles:["admin","..."]         当config/index.js中rolesControl配置开启时，用于控制角色
    roles: {
      role: ["admin"],
      ability: ["READ","WRITE","DELETE"],         ability: ["READ","WRITE"],
      mode: "allOf"              allOf: 数组内所有角色都拥有，返回True oneOf: 数组内拥有任一角色，返回True(等价第1种数据) except: 不拥有数组内任一角色，返回True(取反)
     }
    icon:""                  remix图标
    isCustomSvgIcon:false,        是否是自定义svg图标（默认值：false，如果设置true，那么需要把你的svg拷贝到icon/remixIcon下，然后remixIcon字段配置上你的图标名）
    noKeepAlive:true              当前路由是否不缓存（默认值：false）
    affix:true                    当前路由是否固定多标签页
    badge:"New"                   badge小标签（只支持子级）
    tagHidden:true                当前路由是否不显示多标签页
   }
 */


// 通用路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true,
  },
  {
    path: '/403',
    name: '403',
    component: () => import('@/views/403'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]



// 异步加载路由
export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    meta: {
      title: '数据统计',
      icon: 'icon-shujutongji',
      affix: false,
    },
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index'),
        meta: {
          title: '数据统计',
          icon: 'icon-shujutongji',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/input-manage',
    component: Layout,
    redirect: '/input-manage/materials',
    alwaysShow: true,
    meta: {
      title: '原材料管理',
      icon: 'icon-yuancailiao',
    },
    children: [
      {
        path: 'materials',
        name: 'materials',
        component: () => import('@/views/input-manage/materials'),
        meta: {
          title: '物料管理',
          icon: 'icon-yuancailiao',
        },
      },
      {
        path: 'input-record',
        name: 'input-record',
        component: () => import('@/views/input-manage/input-record'),
        meta: {
          title: '入库日志',
          icon: 'icon-rizhi',
        },
      },
    ],
  },
  {
    path: '/output',
    component: Layout,
    redirect: '/output/manage',
    meta: {
      title: '成品管理',
      icon: 'icon-chanpin',
      affix: false,
    },
    children: [
      {
        path: 'manage',
        name: 'manage',
        component: () => import('@/views/output-manage/output-manage'),
        meta: {
          title: '成品管理',
          icon: 'icon-chanpin',
          affix: true,
        },
      },
      {
        path: 'log',
        name: 'output-log',
        component: () => import('@/views/output-manage/output-log'),
        meta: {
          title: '出库日志',
          icon: 'icon-rizhi',
          affix: true,
        },
      }
    ],
  },
  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/stock',
    meta: {
      title: '库存管理',
      icon: 'icon-kucun',
    },
    children: [
      {
        path: 'stock',
        name: 'stock',
        component: () => import('@/views/stock-manage/stock-manage'),
        meta: {
          title: '库存管理',
          icon: 'icon-kucun',
        },
      },
      {
        path: 'inventory-log',
        name: 'inventory-log',
        component: () => import('@/views/stock-manage/inventory-log'),
        meta: {
          title: '调拨日志',
          icon: 'icon-rizhi',
        },
      }, {
        path: 'return-log',
        name: 'return-log',
        component: () => import('@/views/stock-manage/return-log'),
        meta: {
          title: '退货日志',
          icon: 'icon-rizhi',
        },
      },
    ],
  },
  // {
  //   path: '/error',
  //   name: 'Error',
  //   component: Layout,
  //   redirect: '/error/403',
  //   meta: {
  //     title: '出库管理',
  //     icon: 'error-warning-line',
  //   },
  //   children: [
  //     {
  //       path: '403',
  //       name: 'Error403',
  //       component: () => import('@/views/403'),
  //       meta: {
  //         title: '出库管理',
  //         icon: 'error-warning-line',
  //       },
  //     },
  //     // {
  //     //   path: '404',
  //     //   name: 'Error404',
  //     //   component: () => import('@/views/404'),
  //     //   meta: {
  //     //     title: '日志',
  //     //     icon: 'error-warning-line',
  //     //   },
  //     // },
  //   ],
  // },
  {
    path: '/system',
    name: 'system',
    component: Layout,
    redirect: '/system/user',
    meta: {
      title: '系统管理',
      icon: 'icon-xitongshezhi',
      roles: ['ROLE_SUP_ADMIN'],
    },
    children: [
      {
        path: 'user',
        name: 'userManager',
        component: () => import('@/views/user-manager/user-manager'),
        meta: {
          title: '用户管理',
          icon: 'icon-yonghu',
        },
      },
      {
        path: 'stockStore',
        name: 'stockStore',
        component: () => import('@/views/stockstore-manage/stockstore-manage'),
        meta: {
          title: '仓库管理',
          icon: 'icon-cangku2',
        },
      },
    ],
  },
  {
    path: '/*',
    redirect: '/404',
    hidden: true,
  },
]


// 第一次加载 通用路由
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
})

export default router
